package com.example.screen_data.movie;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class AppService {

    private AppDao appDao;

    @Autowired
    public AppService(AppDao appDao) {
        this.appDao = appDao;
    }

    public Map<String, Object> getData0() {
        return appDao.getData0();
    }
    // 双折线
    public Map<String, Object> getData1() {
        final List<Map<String, Object>> list = appDao.getData1();
        List<String> key = new ArrayList<>();
        List<String> val1 = new ArrayList<>();
        List<String> val2 = new ArrayList<>();
        for(Map<String, Object> map : list) {
            key.add(map.get("date").toString());
            val1.add(map.get("release_cnt").toString());
            val2.add(map.get("date_avg_rating").toString());
        }
        final HashMap<String, Object> returnMap = new HashMap<>();
        returnMap.put("key", key);
        returnMap.put("val1", val1);
        returnMap.put("val2", val2);
        return returnMap;
    }
    // 饼图
    public List<Map<String, Object>> getData2(){
        return appDao.getData2();
    }
    // 词云图
    public List<Map<String, Object>> getData3(){
        return appDao.getData3();
    }
    // 词云图
    public List<Map<String, Object>> getData4(){
        return appDao.getData4();
    }

    public Map<String, Object> getData5() {
        final List<Map<String, Object>> list = appDao.getData5();
        List<String> key = new ArrayList<>();
        List<String> val1 = new ArrayList<>();
        List<String> val2 = new ArrayList<>();
        for (Map<String, Object> map : list) {
            key.add(map.get("genres").toString());
            val1.add(map.get("genres_movie_cnt").toString());
            val2.add(map.get("genres_avg_rating").toString());
        }
        final HashMap<String, Object> returnMap = new HashMap<>();
        returnMap.put("key", key);
        returnMap.put("val1", val1);
        returnMap.put("val2", val2);
        return returnMap;
    }

    public List<Map<String, Object>> getData6(){
        return appDao.getData6();
    }


}
